package yaowen.com.listviewsimpledemo;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.ListView;
import android.widget.SimpleAdapter;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.Objects;

public class MainActivity extends AppCompatActivity {

    private ListView listView;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        listView= (ListView) this.findViewById(R.id.listView);
        SimpleAdapter adapter=new SimpleAdapter(this,getData(),R.layout.user,
                new String[]{"image","userName","userAge","userNum"},
                new int[]{R.id.image,R.id.userName,R.id.userAge,R.id.userNum});
        listView.setAdapter(adapter);

    }
    private ArrayList<HashMap<String,Object>> getData(){
        ArrayList<HashMap<String,Object>> arrayList=new ArrayList<HashMap<String,Object>>();
        //电话号码和名字是随便输入的；
        String num1="15626102865";
        String num2="15626226987";
        String num3="15626212456";
        int i;
        for (i=0;i<10;i++){
            HashMap<String,Object>hashMap=new HashMap<String, Object>();
            hashMap.put("image", R.drawable.icon);
            if (i==0){
                hashMap.put("userName","孟浩宇");
                hashMap.put("userAge",22);
                hashMap.put("userNum",num1);
            } else if(i==1){
                hashMap.put("userName","武则天");
                hashMap.put("userAge",22+i);
                hashMap.put("userNum",num2);
            }else if (i==2){
                hashMap.put("userName","李世民");
                hashMap.put("userAge",220+i);
                hashMap.put("userNum",num3);
            }else {
                hashMap.put("userName","李丽红");
                hashMap.put("userAge",25);
                hashMap.put("userNum","13724734143");
            }
            arrayList.add(hashMap);
        }
        return arrayList;
    }

}
